<?php

/**
 * select_source
 * Selects the source from the config file and creates the db object
 * @param string $source
 * @return mixed $db database object
 */

function select_source( $source ) {
	$db = null;
	global $authorities;
	$s = $authorities[$source];
	switch( $s['db_type'] ) {
		case 'mysql':
			require_once('class.queries.mysql.php');
			$connection_string = sprintf("server=%s; database=%s; username=%s; password=%s;", $s['host'], $s['db_name'], $s['username'], $s['pass'] );	
			$conn = new MysqliDatabase($connection_string);
			$db = new Queries( $conn, $source );
			break;
	}
	
	return( $db );
}

function getSources () {
	global $authorities;
	$op = array();
	if(count($authorities)) {
		foreach($authorities as $key => $val_array) {
		$op[] = array('id' => $val_array['id'], 'name' => $val_array['name'], 'value' => $key, 'description' => $val_array['description']);
		}
	}
	return $op;
}


?>